package springcloud.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import springcloud.feign.AddressOpenfeign;
import springcloud.pojo.Address;
import springcloud.pojo.Order;

import java.util.Random;

/**
 * @Author 咕唧
 * @Date 2022/6/24 21:30
 * @Version 1.0
 */
@RestController
public class OrderController {

    private AddressOpenfeign addressOpenfeign;

    @Autowired
    public void setAddressOpenfeign(AddressOpenfeign addressOpenfeign) {
        this.addressOpenfeign = addressOpenfeign;
    }

    private Random random = new Random();

    @GetMapping("/info/{id}")
    public Order findById(@PathVariable Long id) {
        Order order = new Order();
        order.setItemName("订单名字-----" + random.nextInt());
        order.setId(id);
        order.setPrice(random.nextDouble());

        //我们发现我们还需要地址的数据,但是地址不在当前程序内部,在另外一个服务器的程序里面
        Address address = addressOpenfeign.findById(id);
        order.setAddress(address);

        return order;
    }

    @GetMapping("/test/{aaa}")
    public Address test(@PathVariable Long aaa) {
        return addressOpenfeign.test(aaa);
    }

    @GetMapping("/test22222")
    public String test2222(String aaa) {
        return addressOpenfeign.test2(aaa);
    }

    @GetMapping("/test33333")
    public String test33333(String aaa, int abc) {
        return addressOpenfeign.test3(aaa, abc);
    }

    @GetMapping("/test444444")
    public Address test33333(Address address) {
        return addressOpenfeign.test4(address);
    }

}
